package com.entor.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.entor.model.Msg;
import com.entor.model.National;
import com.entor.model.Partymember;
import com.entor.service.BaseServiceI;
import com.entor.util.ExcelUtil;
@Controller
@RequestMapping("/pmc")
public class PartymemberController extends BaseController<Partymember>{
			
	@Resource(name="partymemberService")	
	private BaseServiceI<Partymember> pm;
			
	@Resource(name="nationalService")	
	private BaseServiceI<National> nal;
		
	
	
	@Override
	public List<Partymember> find(Partymember p){
		
	
		
		return pm.find(p);
		
	}
	
	@Override
	public Msg insert(Partymember p,@RequestParam(required=false,value="file") MultipartFile[] files){
		
		return pm.insert(p);
	}
	
	@Override
	public Msg remove(@PathVariable(value="id") Integer id){
		
		return pm.remove(id);
	}
	
	@Override
	public Msg edit(Partymember t,@RequestParam(required=false,value="file") MultipartFile[] files){
		
		
		return pm.edit(t);
	}
	
	
	
	
	@RequestMapping("/index")
	public String index(){
		
		return "/partymember/index";
	}
	
	
	@RequestMapping("/addoredit")
	public String addoredit(HttpServletRequest req) throws Exception{
		
		

		
		String vals = req.getParameter("vals");
		
		if(vals!=null){
		vals = new String(vals.getBytes("iso-8859-1"),"utf-8");
		Partymember p = JSON.parseObject(vals,Partymember.class);
		req.setAttribute("pb", p);
		}
	
		
		
		return "/partymember/addOrEdit";
	}
	
	@RequestMapping("/notional")
	@ResponseBody
	public List<National> national(National n){
		
		List list = nal.find(n);
		
		return list;
		
	}
	
	
	
	@Override
	public Msg outExcle(String fileName,String datas) {
		Msg m = new Msg("导出失败",false);
		try {
			List<Partymember> list = JSON.parseArray(datas,Partymember.class);
			ExcelUtil.outPartymember(list,fileName);
			m = new Msg("导出成功",false);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return m;
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
